// /*
//  * @Author: WanYiMing
//  * @Date:2024-03-04-16:06
//  * @Description:
//  */

using UnityEngine;

namespace Code.Utility
{
    public class TransformMoveUtils
    {
        private Vector2 _targetRect;
        private float _duration;//持续时间
        private Vector2 _localRectTransform;

        private float _timer = 0f; // 计时器
        private float t ;// 计算移动的进度

        public void SerRectTransformMove(Vector2 localRectTransform,Vector2 targetRect,float duration)
        {
            this._targetRect =targetRect;
            this._duration = duration;
            this._localRectTransform = localRectTransform;
            this._timer = 0;
            this.t = 0;
        }
        
        public Vector3 Moving()
        {
            _timer += Time.deltaTime; // 更新计时器
            // 计算移动的进度
            t = _timer / _duration;
            t = Mathf.Clamp01(t); // 将t限制在0到1之间，确保在指定时间到达目标位置
            // 使用插值移动
            Vector3 moveTowards = Vector3.Lerp(_localRectTransform, _targetRect, t);
            return moveTowards;
        }
        
        public bool RotateEnd()
        {
            if (t>=1)
            {
                return true;
            }
            return false;
        }
    }
}